package com.google.android.material.transformation;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import b.f.l.s;
import java.util.List;

public abstract class ExpandableBehavior extends CoordinatorLayout.c<View> {
    /* access modifiers changed from: private */

    /* renamed from: a  reason: collision with root package name */
    public int f2436a = 0;

    class a implements ViewTreeObserver.OnPreDrawListener {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ View f2437b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ int f2438c;

        /* renamed from: d  reason: collision with root package name */
        final /* synthetic */ c.b.a.b.w.a f2439d;

        a(View view, int i, c.b.a.b.w.a aVar) {
            this.f2437b = view;
            this.f2438c = i;
            this.f2439d = aVar;
        }

        public boolean onPreDraw() {
            this.f2437b.getViewTreeObserver().removeOnPreDrawListener(this);
            if (ExpandableBehavior.this.f2436a == this.f2438c) {
                ExpandableBehavior expandableBehavior = ExpandableBehavior.this;
                c.b.a.b.w.a aVar = this.f2439d;
                expandableBehavior.H((View) aVar, this.f2437b, aVar.a(), false);
            }
            return false;
        }
    }

    public ExpandableBehavior() {
    }

    public ExpandableBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    private boolean F(boolean z) {
        if (!z) {
            return this.f2436a == 1;
        }
        int i = this.f2436a;
        return i == 0 || i == 2;
    }

    /* access modifiers changed from: protected */
    public c.b.a.b.w.a G(CoordinatorLayout coordinatorLayout, View view) {
        List<View> r = coordinatorLayout.r(view);
        int size = r.size();
        for (int i = 0; i < size; i++) {
            View view2 = r.get(i);
            if (e(coordinatorLayout, view, view2)) {
                return (c.b.a.b.w.a) view2;
            }
        }
        return null;
    }

    /* access modifiers changed from: protected */
    public abstract boolean H(View view, View view2, boolean z, boolean z2);

    public boolean h(CoordinatorLayout coordinatorLayout, View view, View view2) {
        c.b.a.b.w.a aVar = (c.b.a.b.w.a) view2;
        if (!F(aVar.a())) {
            return false;
        }
        this.f2436a = aVar.a() ? 1 : 2;
        return H((View) aVar, view, aVar.a(), true);
    }

    public boolean l(CoordinatorLayout coordinatorLayout, View view, int i) {
        c.b.a.b.w.a G;
        if (s.L(view) || (G = G(coordinatorLayout, view)) == null || !F(G.a())) {
            return false;
        }
        int i2 = G.a() ? 1 : 2;
        this.f2436a = i2;
        view.getViewTreeObserver().addOnPreDrawListener(new a(view, i2, G));
        return false;
    }
}
